import sys
import requests
import json
import csv 
import os
urlr='http://zhuce.nafmii.org.cn/fans/publicQuery/releFileProjDataGrid?rows=20&page={}'
headers = {'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36',
        'Referer':'http://zhuce.nafmii.org.cn/fans/publicQuery/manager',
        'Cookie':'Hm_lvt_508be7db52fd6da009f33b1d6a262bd3=1571136780; JSESSIONID=edHZTcStdl3KQQVV6HQc0YLZ5P3VArHm49c7P3llK5z9gi34KG2r!-1036170306',
 }
max=4
csvfile=open('data.csv','w',encoding='gb18030')
writer=csv.writer(csvfile)
writer.writerow(('债券名称','品种','金额','注册或备案','更新时间','项目状态'))
for page in range(1, max): 
    response=requests.get(urlr.format(page),headers=headers).text
    jsonObj = json.loads(response)
    for item in range(len(jsonObj["rows"])):
        writer.writerow((jsonObj["rows"][item]["regFileName"],jsonObj["rows"][item]["regPrdtType"],jsonObj["rows"][item]["regAmount"],jsonObj["rows"][item]["isReg"],jsonObj["rows"][item]["releaseTime"],jsonObj["rows"][item]["leadManagerStatus"]))

       
        
    
    
 
    

   
 